package main

//https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/
func maxScore(cardPoints []int, k int) int {
	//其他的元素长度
	outLen := len(cardPoints) - k - 1
	//其他元素值的和
	outSum := 0
	minSum := 0
	sum := 0
	for i, v := range cardPoints {
		sum += v
		if i <= outLen {
			outSum += v
			minSum = outSum
			continue
		}
		outSum += v - cardPoints[i-outLen-1]
		if outSum < minSum {
			minSum = outSum
		}
	}
	return sum - minSum
}

func main() {
	res := maxScore([]int{1, 2, 3, 4, 5, 6, 1}, 3)
	println(res)
}
